home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / NewsWatcher 2.0d17 Source / source / newswatcher.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-04  |  4.5 KB  |  212 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     NewsWatcher - Macintosh Network News Reader.
  4.     
  5.     Portions copyright © 1990, Apple Computer.
  6.     Portions copyright © 1993, Northwestern University.
  7.  
  8. ------------------------------------------------------------------------------
  9.  
  10.     newswatcher.c
  11.  
  12.     This module contains the main entry point of the program
  13.     and the main event loop.
  14. ----------------------------------------------------------------------------*/
  15.  
  16. #include <string.h>
  17. #include <appleevents.h>
  18.  
  19. #include "glob.h"
  20. #include "activate.h"
  21. #include "close.h"
  22. #include "collapse.h"
  23. #include "draw.h"
  24. #include "init.h"
  25. #include "key.h"
  26. #include "mark.h"
  27. #include "menus.h"
  28. #include "mouse.h"
  29. #include "newart.h"
  30. #include "nntp.h"
  31. #include "prefs.h"
  32. #include "print.h"
  33. #include "util.h"
  34. #include "log.h"
  35. #include "killfile.h"
  36.  
  37.  
  38. /*    FixCursor sets up the type of cursor needed, depending on where the mouse
  39.     pointer is located.  This routine is called in conjunction with WaitNextEvent.
  40. */
  41.  
  42. static void FixCursor (Point mouse, RgnHandle region)
  43. {
  44.     WindowPtr wind;
  45.     RgnHandle arrowRgn,iBeamRgn;
  46.     Rect iBeamRect;
  47.     Point topLeftPt,botRightPt;
  48.     TWindow **info;
  49.     EWindowKind kind;
  50.     TEHandle theTE;
  51.     
  52.     wind = FrontWindow();
  53.     if (!gInBackground && !IsDAWindow(wind)) {
  54.         arrowRgn = NewRgn();
  55.         iBeamRgn = NewRgn();
  56.         SetRectRgn(arrowRgn,-32768,-32768,32767,32767);
  57.         if (IsAppWindow(wind)) {
  58.             info = (TWindow**)GetWRefCon(wind);
  59.             kind = (**info).kind;
  60.             if (kind == kArticle || kind == kMiscArticle ||
  61.                 kind == kPostMessage || kind == kMailMessage) 
  62.             {
  63.                 theTE = (**info).theTE;
  64.                 iBeamRect = (**theTE).viewRect;
  65.                 SetPort(wind);
  66.                 SetPt(&topLeftPt,iBeamRect.left,iBeamRect.top);
  67.                 SetPt(&botRightPt,iBeamRect.right,iBeamRect.bottom);
  68.                 LocalToGlobal(&topLeftPt);
  69.                 LocalToGlobal(&botRightPt);
  70.                 iBeamRect.left = topLeftPt.h;
  71.                 iBeamRect.top = topLeftPt.v;
  72.                 iBeamRect.right = botRightPt.h;
  73.                 iBeamRect.bottom = botRightPt.v;
  74.                 RectRgn(iBeamRgn,&iBeamRect);
  75.             }
  76.         }
  77.         DiffRgn(arrowRgn,iBeamRgn,arrowRgn);
  78.         if (PtInRgn(mouse,iBeamRgn)) {
  79.             SetCursor(&gIBeamCurs);
  80.             CopyRgn(iBeamRgn,region);
  81.         } else {
  82.             SetCursor(&qd.arrow);
  83.             CopyRgn(arrowRgn,region);
  84.         }
  85.         DisposeRgn(arrowRgn);
  86.         DisposeRgn(iBeamRgn);
  87.     }
  88. }
  89.  
  90.  
  91. /*    DoQuit closes windows prior to the quitting of the application.
  92. */
  93.  
  94. static Boolean DoQuit (void)
  95. {
  96.     WindowPtr wind;
  97.     TWindow **info;
  98.     
  99.     while (true) {
  100.         wind = FrontWindow();
  101.         while (wind && (wind == gFullGroupWindow || 
  102.             !IsAppWindow(wind) || IsStatusWindow(wind)))
  103.             wind = (WindowPtr)((WindowPeek)wind)->nextWindow;
  104.         if (wind == nil) break;
  105.         if (!DoCloseWindow(wind)) return false;
  106.     }
  107.     if (gFullGroupWindow != nil) DoCloseWindow(gFullGroupWindow);
  108.     return true;
  109. }
  110.  
  111.  
  112.  
  113. /* MainEvent - main event loop. */
  114.  
  115. static void MainEvent (void)
  116. {
  117.     EventRecord ev;
  118.     RgnHandle cursorRgn;
  119.     Boolean    gotEvt;
  120.     WindowPtr wind;
  121.     TWindow **info;
  122.     EWindowKind kind;
  123.  
  124.     cursorRgn = NewRgn();
  125.  
  126.     while (!gDone) {
  127.     
  128.         gCancel = false;
  129.         
  130.         wind = FrontWindow();
  131.         if (IsStatusWindow(wind)) {
  132.             CloseStatusWindow();
  133.         } else if (IsAppWindow(wind)) {
  134.             info = (TWindow**)GetWRefCon(wind);
  135.             kind = (**info).kind;
  136.             if (kind == kArticle || kind == kMiscArticle  ||
  137.                 kind == kPostMessage || kind == kMailMessage)
  138.                 TEIdle((**info).theTE);
  139.         }
  140.         
  141.         AdjustMenus();
  142.         
  143.         CloseIdleNewsConnection(false);
  144.             
  145.         gotEvt = WaitNextEvent(everyEvent,&ev,GetCaretTime(),cursorRgn);
  146.         
  147.         FixCursor(ev.where,cursorRgn);
  148.         
  149.         if (gotEvt) {
  150.             switch (ev.what) {
  151.                 case mouseDown:
  152.                     HandleMouseDown(&ev);
  153.                     break;
  154.                 case keyDown:
  155.                 case autoKey:
  156.                     HandleKeyDown(wind, &ev);
  157.                     break;
  158.                 case activateEvt:
  159.                     HandleActivate((WindowPtr)ev.message,
  160.                         ((ev.modifiers & activeFlag) != 0)); 
  161.                     break;
  162.                 case updateEvt:
  163.                     HandleUpdate((WindowPtr)(ev.message));
  164.                     break;
  165.                 case app4Evt:
  166.                     HandleSuspendResume(ev.message);
  167.                     break;
  168.                 case kHighLevelEvent:
  169.                     AEProcessAppleEvent(&ev);
  170.                     break;
  171.             }
  172.             FixCursor(ev.where,cursorRgn);
  173.         }
  174.         
  175.         if (gDone) gDone = DoQuit();
  176.     }
  177.     
  178.     DisposeRgn(cursorRgn);
  179.         
  180.     CloseIdleNewsConnection(true);
  181.     
  182.     EndNNTP();
  183.     WritePrefs();
  184.     
  185.     if (gPrefs.logActionsToFile) CloseLogFile();
  186.     
  187.     #ifdef FILTERS
  188.         WriteKillFile();
  189.     #endif
  190.  
  191.     memset(gPrefs.remotePassword,'%', sizeof(gPrefs.remotePassword));
  192.     memset(gAutoFetchPass,'%', sizeof(gAutoFetchPass));
  193. }
  194.  
  195.  
  196. /* main - main entry point. */
  197.  
  198. void main (void)
  199. {
  200.     SetApplLimit(GetApplLimit() - 20000);
  201.     MaxApplZone();
  202.     MoreMasters();
  203.     MoreMasters();
  204.     MoreMasters();
  205.     MoreMasters();
  206.     MoreMasters();
  207.     Init();
  208.     UnloadSeg(Init);
  209.     MainEvent();
  210.     ExitToShell();    /* Yes, you really do need to do this! */
  211. }
  212.